package dev.blogmoon.cn.system.convert;

import dev.blogmoon.cn.system.entity.SysMenu;
import dev.blogmoon.cn.system.module.MenuTreeDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper(uses = TypeConversionWorker.class)
public interface SysMenuConvert {

    SysMenuConvert INSTANCE = Mappers.getMapper(SysMenuConvert.class);

    @Mapping(source = "id", target = "id")
    @Mapping(source = "meta",target = "meta",qualifiedByName = "jsonStringToMenuMetaObject")
    MenuTreeDTO toDto(SysMenu entity);


    @Mapping(source = "id", target = "id")
    @Mapping(source = "meta",target = "meta",qualifiedByName = "toJsonString")
    SysMenu toEntity(MenuTreeDTO dto);

    @Mapping(source = "id", target = "id")
    @Mapping(source = "meta",target = "meta",qualifiedByName = "jsonStringToMenuMetaObject")
    List<MenuTreeDTO> toDtoList(List<SysMenu> entityList);
}
